package main

import (
	"fmt"
	"strings"
)

//闭包
func addUpper() func (int) int{
	var n int = 10
	return func (x int) int {
		n = n + x
		return n
	}
}

//闭包不用每次都传入参数
func hasSuffix(suffix string) func (string) string {

	return func (name string) string {
		if !strings.HasSuffix(name,suffix) {
			return name+suffix
		}
		return name
	}
}

func main(){
	f := addUpper()
	fmt.Println(f(1))  //11
	fmt.Println(f(2))  //13

	f2 := hasSuffix(".jpg")
	fmt.Println(f2("name"))
	fmt.Println(f2("test.jpg")) 
	
}

